package cn.itcast.service.mill.impl;

import cn.itcast.dao.cargo.FactoryDao;
import cn.itcast.domain.cargo.Factory;
import cn.itcast.service.mill.MillService;
import cn.itcast.utils.UUIDUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service //dubbo注解
public class MillServiceImpl implements MillService {

	@Autowired
	FactoryDao factoryDao;

	//pageHelper完成分页
	@Override
	public PageInfo findByPage(int page, int size) {

		//1.调用PageHelper的静态方式设置参数
		PageHelper.startPage(page,size);
		//2.查询所有
		List<Factory> list = factoryDao.findAll();

		//3.将上个查询的list集合使用PageInfo封装
		return new PageInfo<Factory>(list);
	}

	@Override
	public List<Factory> findAll(String companyId) {
		return factoryDao.findAll();
	}



	//新增厂商
	@Override
	public void save(Factory factory) {
		//给厂商设置id
		factory.setId(UUIDUtils.getId());
		factoryDao.save(factory);
	}

	//更新厂商
	@Override
	public void update(Factory factory) {
		factoryDao.update(factory);
	}

	//根据id查询信息
	@Override
	public Factory findById(String id) {
		return factoryDao.findById(id);
	}

	//删除厂商
	@Override
	public void deleteById(String id) {
		factoryDao.deleteById(id);
	}
}
